package com.workflow.engine.parser.utils;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class JsoupHelper {

	/**
	 * 根据id获得值
	 * @param id
	 * @return
	 */
	public static String getStringById(Document doc, String id){
		return doc.getElementById(id)!=null?doc.getElementById(id).val():"";
	}

	public static String getAttributeByElementId(Document doc, String id, String attrKey){
		Element element = doc.getElementById(id)!=null ? doc.getElementById(id) : null;
		if (element == null) {
			return null;
		}
		return element.attr(attrKey);
	}

	/**
	 * 获得详情     
	 * @return
	 */
	public static Elements getContentElements(Document doc, String regex){
		return doc.select(regex);
	}
	
	/**
	 * 获得详情根据class
	 * @return
	 */
	public static Elements getElementsByClass(Document doc, String classId){
		return doc.getElementsByClass(classId);
	}
	
	/**
	 * 获得详情根据id
	 * @return
	 */
	public static Element getElementById(Document doc, String id){
		return doc.getElementById(id);
	}

	/**
	 * 获得详情根据name
	 * @return
	 */
	public static Element getElementsByName(Document doc, String nameValue){
		return doc.getElementsByAttributeValue("name", nameValue).get(0);
	}

	/**
	 * 获得详情根据name
	 * @return
	 */
	public static Elements getElementsByTagName(Document doc, String nameValue){
		return doc.getElementsByTag(nameValue);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
